//
//  NameImageTableViewCell.m
//  GoldBook
//
//  Created by wmz on 2021/8/19.
//  Copyright © 2021 wmz. All rights reserved.
//

#import "NameImageTableViewCell.h"
@interface NameImageTableViewCell()
@property(nonatomic,strong)UILabel *nameLB;
@property(nonatomic,strong)UIImageView *iconIV;
@end
@implementation NameImageTableViewCell

- (void)hd_setupViews{
    [self.contentView addSubview:self.nameLB];
    [self.contentView addSubview:self.iconIV];
    @HDWeakify(self)
    self.iconIV.add_selectEvent(^(UIImage * _Nonnull image) {
        @HDStrongify(self)
        if (self.model.rightUserInable) {
            self.iconIV.image = image;
        }
    });
    
}

- (void)setGNModel:(id)data{
    self.model = data;
    self.model.notCacheHeight = YES;
    self.nameLB.text = GNFillEmpty(self.model.title);
    self.nameLB.textColor = self.model.titleColor;
    self.nameLB.font = self.model.titleFont;
    if ([self.model.imageTitle hasPrefix:@"/"] && [self.model.imageTitle hasSuffix:@"g"]) {
        [self.iconIV sd_setImageWithURL:[NSURL URLWithString:GNFillImage(self.model.imageTitle)]];
    }else{
        self.iconIV.image = [UIImage imageNamed:self.model.imageTitle];
    }
    self.iconIV.userInteractionEnabled = self.model.rightUserInable;
    if (self.model.rightUserInable) {
        if (!self.model.imageTitle) {
            self.iconIV.image = [UIImage imageNamed:@"mine_14"];
        }
    }
    [self setNeedsUpdateConstraints];
}

- (void)updateConstraints{
    [self.nameLB mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(10);
        make.right.mas_equalTo(-10);
    }];
    
    [self.iconIV mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLB.mas_bottom).offset(13);
        make.left.equalTo(self.nameLB);
        make.size.mas_equalTo(self.model.imageSize);
        make.bottom.mas_equalTo(-10);
    }];
    [super updateConstraints];
}

- (UILabel *)nameLB{
    if (!_nameLB) {
        _nameLB = UILabel.new;
        _nameLB.numberOfLines = 0;
    }
    return _nameLB;
}

- (UIImageView *)iconIV{
    if (!_iconIV) {
        _iconIV = UIImageView.new;
        _iconIV.image = PostDefaultIcon;
    }
    return _iconIV;
}

@end
